package com.qumitech.visualnovel.controller.rest;

import com.qumitech.visualnovel.component.annotation.RequireWhiteList;
import com.qumitech.visualnovel.model.common.BaseRsp;
import com.qumitech.visualnovel.model.common.ResultEnum;
import com.qumitech.visualnovel.controller.vo.player.UserResetRecordVO;
import com.qumitech.visualnovel.controller.vo.player.UserResetVO;
import com.qumitech.visualnovel.pubdef.dto.voiceroom.*;
import com.qumitech.visualnovel.pubdef.dto.voiceroom.query.VoiceRoomAdminQueryDTO;
import com.qumitech.visualnovel.pubdef.dto.voiceroom.query.VoiceRoomProfitQueryDTO;
import com.qumitech.visualnovel.pubdef.dto.voiceroom.query.VoiceRoomPropertyChangeQueryDTO;
import com.qumitech.visualnovel.pubdef.dto.voiceroom.query.VoiceRoomSupplementQueryDTO;
import com.qumitech.visualnovel.service.voiceRoom.VoiceRoomManageService;
import com.google.common.collect.ImmutableMap;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/api/voiceroom/manage")
public class VoiceRoomManageController {

    @Autowired
    private VoiceRoomManageService voiceRoomManageService;

    @RequireWhiteList
    @GetMapping("")
    public BaseRsp listVoiceRoom(VoiceRoomAdminQueryDTO queryDTO) {
        return voiceRoomManageService.listVoiceRoom(queryDTO);
    }

    @RequireWhiteList
    @PutMapping("/{room_id}")
    public BaseRsp updateVoiceRoom(@PathVariable("room_id") String roomId,
                                   @RequestBody VoiceRoomAdminUpdateDTO updateDTO) {
        updateDTO.setRoomId(roomId);
        voiceRoomManageService.updateVoiceRoom(updateDTO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequireWhiteList
    @GetMapping("/property_change")
    public BaseRsp listVoiceRoomPropertyChange(VoiceRoomPropertyChangeQueryDTO queryDTO) {
        return new BaseRsp(ResultEnum.SUCCESS, ImmutableMap.of("property_changes", voiceRoomManageService.listVoiceRoomPropertyChange(queryDTO),
                "count", voiceRoomManageService.countVoiceRoomPropertyChange(queryDTO)));
    }


    @RequireWhiteList
    @GetMapping("/profit/{room_id}")
    public BaseRsp VoiceRoomProfitStatistic(@PathVariable("room_id") String roomId) {
        return new BaseRsp(ResultEnum.SUCCESS, voiceRoomManageService.getVoiceRoomProfitStatistic(roomId));
    }

    @RequireWhiteList
    @GetMapping("/profit")
    public BaseRsp VoiceRoomProfit(VoiceRoomProfitQueryDTO queryDTO) {

        return new BaseRsp(ResultEnum.SUCCESS, ImmutableMap.of("profit", voiceRoomManageService.listVoiceRoomProfit(queryDTO),
                "count", voiceRoomManageService.countVoiceRoomProfit(queryDTO)));
    }

    @RequireWhiteList
    @GetMapping("/rebate/withdraw")
    public BaseRsp listVoiceRoomRebateWithdraw(RebateWithdrawQueryDTO queryDTO) {
        return voiceRoomManageService.listVoiceRoomRebateWithdraw(queryDTO);
    }

    @RequireWhiteList
    @PutMapping("/rebate/{room_id}")
    public BaseRsp updateVoiceRoomRebate(@PathVariable("room_id") String roomId, @RequestBody VoiceRoomRebateUpdateDTO updateDTO) {
        updateDTO.setRoomId(roomId);
        return voiceRoomManageService.updateVoiceRoomRebate(updateDTO);
    }

    @RequireWhiteList
    @PutMapping("/rebate/withdraw/{id}")
    public BaseRsp verifyVoiceRoomRebateWithdraw(@PathVariable("id") Long id,
                                                 @RequestBody RebateWithdrawUpdateDTO updateDTO) {
        updateDTO.setId(id);
        return voiceRoomManageService.verifyVoiceRoomRebateWithdraw(updateDTO);
    }

    @RequireWhiteList
    @GetMapping("/rebate/config/{room_id}")
    public BaseRsp listRebateConfig(@PathVariable("room_id") String roomId) {
        return voiceRoomManageService.listRebateConfig(roomId);
    }


    @RequireWhiteList
    @PutMapping("/rebate/supplement/{room_id}")
    public BaseRsp updateVoiceRoomRebateSupplement(@PathVariable("room_id") String roomId,
                                                   @RequestBody RebateAddDTO dto) {
        dto.setRoomId(roomId);
        return voiceRoomManageService.updateVoiceRoomRebateSupplement(dto);
    }

    @RequireWhiteList
    @GetMapping("/rebate/supplement")
    public BaseRsp listVoiceRoomRebateSupplement(VoiceRoomSupplementQueryDTO queryDTO) {
        return new BaseRsp(ResultEnum.SUCCESS, ImmutableMap.of("supplement", voiceRoomManageService.listVoiceRoomRebateSupplement(queryDTO),
                "count", voiceRoomManageService.countVoiceRoomRebateSupplement(queryDTO)));
    }


    @RequireWhiteList
    @GetMapping("/config")
    public BaseRsp listDefaultConfig() {
        return voiceRoomManageService.listDefaultConfig();
    }


    @RequireWhiteList
    @PostMapping("/config")
    public BaseRsp addDefaultConfig(@RequestBody VoiceRoomDefaultConfigDTO defaultConfigDTO) {
        voiceRoomManageService.addDefaultConfig(defaultConfigDTO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequireWhiteList
    @PutMapping("/config/{default_config_id}")
    public BaseRsp updateDefaultConfig(@PathVariable("default_config_id") long defaultConfigId,
                                       @RequestBody VoiceRoomDefaultConfigDTO defaultConfigDTO) {
        defaultConfigDTO.setId(defaultConfigId);
        voiceRoomManageService.updateDefaultConfig(defaultConfigDTO);
        return new BaseRsp(ResultEnum.SUCCESS);
    }

    @RequireWhiteList
    @DeleteMapping("/config/{default_config_id}")
    public BaseRsp deleteDefaultConfig(@PathVariable("default_config_id") long defaultConfigId) {
        voiceRoomManageService.deleteDefaultConfig(defaultConfigId);
        return new BaseRsp(ResultEnum.SUCCESS);
    }


    @GetMapping("/room_type")
    public BaseRsp getVoiceRoomType() {
        return voiceRoomManageService.getVoiceRoomType();
    }


    @GetMapping("/rebate/bill")
    public BaseRsp getVoiceRoomRebateBill(VoiceRoomRebateBillAdminQueryDTO queryDTO) {
        return voiceRoomManageService.getVoiceRoomRebateBill(queryDTO);
    }

    @RequireWhiteList
    @PutMapping("/{room_id}/rebate/change")
    public BaseRsp changeVoiceRoomRebate(@PathVariable("room_id") String roomId,
                                         @RequestBody VoiceRoomRebateAdminDTO rebateAdminDTO) {
        rebateAdminDTO.setRoomId(roomId);
        return voiceRoomManageService.changeVoiceRoomRebate(rebateAdminDTO);
    }

    @GetMapping(value = "/{room_id}/reset")
    public BaseRsp getVoiceRoomReset(@PathVariable(value="room_id") String roomId)
    {
        return voiceRoomManageService.getVoiceRoomReset(roomId);
    }

    @PutMapping(value = "/{room_id}/reset")
    public BaseRsp resetVoiceRoom(@PathVariable(value="room_id") String roomId,
                                  @RequestBody UserResetVO userResetVO)
    {
        return voiceRoomManageService.resetVoiceRoom(userResetVO);
    }

    @GetMapping(value = "/reset_record")
    public BaseRsp getResetRecords(UserResetRecordVO resetRecordVO)
    {
        return voiceRoomManageService.getVoiceRoomResetRecords(resetRecordVO);
    }

}
